package org.zsl.entity;

import org.junit.Test;
import org.springframework.aot.hint.annotation.Reflective;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class FactoryTestor
{
    @Test
    public  void testStaticFactory(){

         Customer customer  = CustomerFactory.getInstance(); // 类方法

        System.out.println(customer);
    }

    @Test
    public void testUnStaticFactory(){

         CustomerFactory2 factory = new CustomerFactory2();
         Customer customer = factory.getInstance(); // 实例方法

        System.out.println(customer);
    }

    @Test
    public  void  testStaticFactoryInSpring(){

        /**
         *     <bean id="staticObject" class="org.zsl.entity.CustomerFactory" factory-method="getInstance"></bean>
         *
         *     由反射机制 完成 对象的创建 和 其他初始化
         * */

        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
       Customer customer = (Customer) context.getBean("staticObject");

        System.out.println(customer);
    }

    @Test
    public  void  testUnStaticFactoryInSpring(){

        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
        Customer customer = (Customer) context.getBean("unStaticCustomer");

        System.out.println(customer);
    }

}
